package com.my.xq.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import com.my.xq.domain.CourtQueryParam;
import com.my.xq.domain.entity.Court;
import com.sskj.core.query.annotation.DynamicQuery;
import com.sskj.core.repository.GenericRepository;

public interface CourtRepository extends GenericRepository<Court, String> {
	@DynamicQuery
	Page<Court> findPage(CourtQueryParam cqp, Pageable pageable);

	@Query("SELECT r FROM Court r where r.name like CONCAT('%',?1,'%')"
			+ " AND r.id not IN (SELECT t.courtid FROM Plan_Court t where t.planid=?2)")
	List<Court> findNotSelectedCourt(String courtName, String planId);

	@Query("SELECT r FROM Court r where r.id IN (SELECT t.courtid FROM Plan_Court t where t.planid=?1)")
	List<Court> findSelectedCourt(String planId);

	@Query(" SELECT r FROM Court r where r.name = ?1 ")
	Court findByName(String name);
}
